<?php

class TreeNode
{
	/**
	 * @var integer
	 */
	private $_id;
	
	/**
	 * @var array
	 */
	private $_element;
	
	/**
	 * @var $_level integer
	 */
	private $_level = 0;
	
	/**
	 * Array of nodes.
	 * 
	 * @var array
	 */
	private $_children;
	
	public function __construct($id, $element)
	{
		$this->setId($id);
		$this->setElement($element);
	}
	
	/**
	 * @return array
	 */
	public function getElement() {
		return $this->_element;
	}
	
	/**
	 * @return integer
	 */
	public function getId() {
		return $this->_id;
	}
	
	/**
	 * @param array $element
	 * @return void
	 */
	public function setElement($element) {
		$this->_element = $element;
	}
	
	/**
	 * @param integer $id
	 * @return void
	 */
	public function setId($id) {
		$this->_id = $id;
	}
	
	/**
	 * @param TreeNode $node
	 */
	public function addChild($node)
	{
		$this->_children[$node->getId()] = $node;
	}
	
	/**
	 * @return array
	 */
	public function getChilds()
	{
		return $this->_children;
	}
	/**
	 * @param integer $level
	 */
	public function setLevel($level) {
		$this->_level = $level;
	}
	
	/**
	 * @return integer
	 */
	public function getLevel() {
		return $this->_level;
	}
	
	/**
	 * получить число дочерних элементов
	 */
	public function getChildCount() {
		return count($this->_children);
	}
}
